/*
 * Copyright (c) 2009-2013 EvTech Project
 * All rights reserved.
 * 
 * This file is part of Game packet.
 *
 * Game packet is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Game packet is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Game packet.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package fi.honkalampisaatio.game.game;


import java.awt.event.KeyListener;
import java.util.ArrayList;

import javax.swing.JPanel;

import fi.honkalampisaatio.game.xml.Setup;
import fi.honkalampisaatio.game.xml.UserSetting;



/**
 * Tämä luokka vastaa pelin esittämisestä näytällä.
 * Paneeli käynnistää itse pelin ja hoitaa sen kaikki
 * toimenpiteet apuluokkien avulla. Jatkossa voi olla fiksua
 * nimetä luokka vain Game:ksi. Nyt kuitenkin selvyyden vuoksi
 * mukana nimessä myäs panel.
 * 
 * 
 * @author Jussi Nuutinen
 *
 */
public abstract class GamePanel extends JPanel implements KeyListener {

	private static final long serialVersionUID = 9174199123635871044L;
	
	//GameEventListener
	protected GameEventListener geListener = null;
	
	protected ArrayList<UserSetting> userList = null;
	@SuppressWarnings("rawtypes")
	private Class settingsClass;


	@SuppressWarnings("rawtypes")
	public GamePanel(Class settingsClass) {
		this.addKeyListener(this);
		this.settingsClass = settingsClass;
	}

	@SuppressWarnings("rawtypes")
	public Class getSettingsClass()
	{
		return this.settingsClass;
	}
	
	public abstract void startGame();


	public abstract void setGameSettings(String setupFileName);
	
	public abstract void setLanguage(String languageFileName);

	
	public abstract void init(Setup setupData);
	
	/**
	 * Tätä funktiota kutsuu GameRunner kun peli on päättynyt...
	 */
	public void gameEnd() {
		
		GameEvent ge = new GameEvent(this,GameEvent.TYPE.GAME_END);
		this.fireGameEvent(ge);
	}
	
	
	// Lisää poista GameEventListener
	public void setGameEventListener(GameEventListener gle) {
		this.geListener = gle;
	}
	
	public void removeGameEventListener(GameEventListener gle) {
		if (this.geListener == gle) {
			this.geListener = null;
		}
	}
	
	protected void fireGameEvent(GameEvent ge) {
		if (this.geListener != null)
			this.geListener.gameEventOccurred(ge);
	}


	public void setUsers(ArrayList<UserSetting> userList) {
		this.userList = userList;
	}

	public ArrayList<UserSetting> getUsers() {
		return userList;
	}
}
